﻿using System;
using System.Collections.Generic;
using Z.GenerateIconProject.WinForm.BL;

namespace Z.GenerateIconProject.WinForm.BWL
{
    public class GenerateProject
    {
        public static void Execute(bool copyIcon)
        {
            List<ProjectConfig> list = IconLibraryHelper.GetConfigs();
            foreach (ProjectConfig item in list)
            {
                var manager = new GenerateProjectManager(item);

                Result result = manager.IsValid();
                if (!result)
                {
                    throw new Exception("Something wrong! See message.");
                }

                // Setup
                manager.EnsureDirectoryExists();
                manager.CleanDirectory();

                // Support File
                manager.GenerateSupportFile();
                manager.GenerateSupportIconFile();

                // Project File
                manager.GenerateProjectFile();
                manager.GenerateProjectIconFile();

                if (copyIcon)
                {
                    // Copy Icon
                    manager.CopyIcon();
                }
            }
        }
    }
}